#ifndef THREAD_LATCH_H
#define THREAD_LATCH_H

#include "utility/Noncopyable.h"

#include <condition_variable>
#include <mutex>

class Latch final {
public:
    explicit Latch(std::ptrdiff_t expected): 
        _cv{}, _mutex{}, _counter{expected} {};
    ~Latch();

    void count_down(std::ptrdiff_t update = 1);
    void wait() const;

private:
    NONCOPYABLE(Latch);

    mutable std::condition_variable _cv;
    mutable std::mutex _mutex;
    std::ptrdiff_t _counter;

};



#endif